const LeacotsDao = require('../dao/leacots-dao')
const BaseServices = require('./base-service')

const {formatTime,parseTime,getRelativeTime} = require('../utils/date-utils')

class LeacotsServices extends BaseServices {
    constructor(dao = new LeacotsDao()) {
        super();
        this.dao = dao
    }

    /**
     * 获取留言列表
     * @param pageIndex
     * @param pageSize
     * @param options
     * @returns {*}
     */
    async getLeacotsList (pageIndex = 1,pageSize = 20){
        const RowsDataPacket = await this.dao.getLeacotsList(pageIndex,pageSize)
        const pattern = "{y}年{m}月{d}日 {h}:{i}:{s}"
        RowsDataPacket.forEach(item => {
            const date = new Date(item.create_time.replace(/-/g, "/"));
            item.create_time = getRelativeTime(Date.parse(date))
        })
        return RowsDataPacket
    }

    /**
     * 添加留言
     * @param leacots
     * @returns {*}
     */
    insertLeacots (leacots){
        return this.dao.insertLeacots(leacots)
    }

    /**
     * 更新留言
     * @param leacots
     * @returns {*}
     */
    updateLeacots (leacots){
        return this.dao.updateLeacots(leacots)
    }
}

module.exports = LeacotsServices;
